package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TBOrderSpread;
import com.ruoyi.system.service.ITBOrderSpreadService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单分期付款Controller
 * 
 * @author pspyy
 * @date 2022-03-09
 */
@RestController
@RequestMapping("/system/orderSpread")
@Api("订单分期付款")
public class TBOrderSpreadController extends BaseController
{
    @Autowired
    private ITBOrderSpreadService tBOrderSpreadService;

    /**
     * 查询订单分期付款列表
     */
    @PreAuthorize("@ss.hasPermi('system:orderSpread:list')")
    @GetMapping("/list")
    @ApiOperation("查询订单分期付款列表")
    public TableDataInfo list(TBOrderSpread tBOrderSpread)
    {
        startPage();
        List<TBOrderSpread> list = tBOrderSpreadService.selectTBOrderSpreadList(tBOrderSpread);
        return getDataTable(list);
    }

    /**
     * 导出订单分期付款列表
     */
    @PreAuthorize("@ss.hasPermi('system:orderSpread:export')")
    @Log(title = "订单分期付款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出订单分期付款列表")
    public void export(HttpServletResponse response, TBOrderSpread tBOrderSpread)
    {
        List<TBOrderSpread> list = tBOrderSpreadService.selectTBOrderSpreadList(tBOrderSpread);
        ExcelUtil<TBOrderSpread> util = new ExcelUtil<TBOrderSpread>(TBOrderSpread.class);
        util.exportExcel(response, list, "订单分期付款数据");
    }

    /**
     * 获取订单分期付款详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:orderSpread:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取订单分期付款详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tBOrderSpreadService.selectTBOrderSpreadById(id));
    }

    /**
     * 新增订单分期付款
     */
    @PreAuthorize("@ss.hasPermi('system:orderSpread:add')")
    @Log(title = "订单分期付款", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增订单分期付款")
    public AjaxResult add(@RequestBody TBOrderSpread tBOrderSpread)
    {
        return toAjax(tBOrderSpreadService.insertTBOrderSpread(tBOrderSpread));
    }

    /**
     * 修改订单分期付款
     */
    @PreAuthorize("@ss.hasPermi('system:orderSpread:edit')")
    @Log(title = "订单分期付款", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改订单分期付款")
    public AjaxResult edit(@RequestBody TBOrderSpread tBOrderSpread)
    {
        return toAjax(tBOrderSpreadService.updateTBOrderSpread(tBOrderSpread));
    }

    /**
     * 删除订单分期付款
     */
    @PreAuthorize("@ss.hasPermi('system:orderSpread:remove')")
    @Log(title = "订单分期付款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除订单分期付款")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tBOrderSpreadService.deleteTBOrderSpreadByIds(ids));
    }
}
